﻿using Domain.Entitys;
using Domain.Repositorys;
using EFCore.Migrations;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EFCore.Repositorys
{
    public class EIRepository:IEIRepositoy
    {
		private readonly MyDbContext myDbContext;

		public EIRepository(MyDbContext myDbContext)
		{
			this.myDbContext = myDbContext;
		}

		public async Task<int> EIAdd(EI eI)
		{
			await myDbContext.EI.AddAsync(eI);
			return await myDbContext.SaveChangesAsync();
		}

		public async Task<List<EI>> EISelectID(string name)
		{
			return await myDbContext.EI.Where(c => c.HumanName == name).ToListAsync();
		}

		public async Task<int> EIUpdate(EI eI)
		{
			myDbContext.EI.Update(eI);
			return await myDbContext.SaveChangesAsync();
		}

		public async Task<int> EIUpdateSX(EI ei)
		{
			EI err = await myDbContext.EI.FirstOrDefaultAsync(e => e.EinId == ei.EinId);
			err.CheckStatus = ei.CheckStatus;
			err.Checker = ei.Checker;
			err.CheckTime = ei.CheckTime;
			myDbContext.EI.Update(err);
			return await myDbContext.SaveChangesAsync();
		}
	}
}
